package cc.fs.study.pinyin;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cc.fs.study.R;

public class PinyinActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private TextView dialogView;
    private PinyinAdapter adapter;
    private List<Contacts> list = new ArrayList<>();
    private SideBar sideBar;
    private ScrollRecyclerViewHelper scrollRecyclerViewHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pinyin);

        list.add(new Contacts("北京", HanziToPinyin.getPinYin("北京")));
        list.add(new Contacts("深圳", HanziToPinyin.getPinYin("深圳")));
        list.add(new Contacts("广州", HanziToPinyin.getPinYin("广州")));
        list.add(new Contacts("南京", HanziToPinyin.getPinYin("南京")));
        list.add(new Contacts("上海", HanziToPinyin.getPinYin("上海")));
        list.add(new Contacts("南昌", HanziToPinyin.getPinYin("南昌")));
        list.add(new Contacts("北海", HanziToPinyin.getPinYin("北海")));
        list.add(new Contacts("哈尔滨", HanziToPinyin.getPinYin("哈尔滨")));
        list.add(new Contacts("大连", HanziToPinyin.getPinYin("大连")));
        list.add(new Contacts("新疆", HanziToPinyin.getPinYin("新疆")));
        list.add(new Contacts("西藏", HanziToPinyin.getPinYin("西藏")));
        list.add(new Contacts("青岛", HanziToPinyin.getPinYin("青岛")));
        list.add(new Contacts("台湾", HanziToPinyin.getPinYin("台湾")));
        list.add(new Contacts("河南", HanziToPinyin.getPinYin("河南")));
        list.add(new Contacts("海南", HanziToPinyin.getPinYin("海南")));
        list.add(new Contacts("山东", HanziToPinyin.getPinYin("山东")));
        list.add(new Contacts("天津", HanziToPinyin.getPinYin("天津")));
        list.add(new Contacts("吉林", HanziToPinyin.getPinYin("吉林")));
        list.add(new Contacts("湖南", HanziToPinyin.getPinYin("湖南")));
        list.add(new Contacts("四川", HanziToPinyin.getPinYin("四川")));
        list.add(new Contacts("重庆", HanziToPinyin.getPinYin("重庆")));
        list.add(new Contacts("佛山", HanziToPinyin.getPinYin("佛山")));
        list.add(new Contacts("梅州", HanziToPinyin.getPinYin("梅州")));
        list.add(new Contacts("厦门", HanziToPinyin.getPinYin("厦门")));
        list.add(new Contacts("湖北", HanziToPinyin.getPinYin("湖北")));
        list.add(new Contacts("阿里", HanziToPinyin.getPinYin("阿里")));
        list.add(new Contacts("1线天", HanziToPinyin.getPinYin("1线天")));
        list.add(new Contacts("2重门", HanziToPinyin.getPinYin("2重门")));
        list.add(new Contacts("wuli涛涛", HanziToPinyin.getPinYin("wuli涛涛")));
        list.add(new Contacts("_12138", HanziToPinyin.getPinYin("_12138")));

        adapter = new PinyinAdapter(list);
        recyclerView = (RecyclerView) findViewById(R.id.recycleView);
        dialogView = (TextView) findViewById(R.id.dialogView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);


        sideBar = (SideBar) findViewById(R.id.sidebar);
        sideBar.setTextView(dialogView);
        sideBar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
            @Override
            public void onTouchingLetterChanged(String s) {
                if (adapter != null) {
                    scrollRecyclerViewHelper.moveToPosition(adapter.getPositionForSection(s));
                }
            }
        });

        scrollRecyclerViewHelper = new ScrollRecyclerViewHelper(recyclerView);

    }
}
